﻿using LanDBom.Models;
using LanDBom.Models.Technology;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LanDBom.Models.Entity;

namespace LanDBom.Controllers
{
    public class TechnologyController : Controller
    {
        Get_Steelmaking steelmaking = new Get_Steelmaking();
        Get_Library library = new Get_Library();
        Del del = new Del();
        Modify_Stee modify_stee = new Modify_Stee();
        LDbaseEntities db = new LDbaseEntities();
        // GET: Technology
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Technology(int ST_ID=-99)
        {
            var liststee = steelmaking.get_STEE();
            ViewBag.liststee = liststee;
            var listlibrary = library.get_Library(ST_ID);
            ViewBag.listlibrary = listlibrary;
            return View();
        }
        //删除一个工艺大类
        public ActionResult Del_steelmaking(int ST_ID)
        {
            //先删除同一分类下的所有工艺
            libray libray = del.Getstlib(ST_ID);
            del.DelStLibray(libray);


            //再删除工艺种类
            Steelmaking steel = del.Getstee(ST_ID);
            int rows = del.DelSteelmaking(steel);
            string msg = rows > 0 ? "删除成功" : "删除失败";
            return Content(msg, "text/plain");

        }
        //删除单一工艺
        public ActionResult Del_libray(int LI_ID)
        {
            libray libray = del.Getlib(LI_ID);

            int rows = del.DelLibray(libray);

            string msg = rows > 0 ? "删除成功" : "删除失败";
            return Content(msg, "text/plain");

        }

        //修改工艺种类
        [HttpPost]
        public ActionResult ModifyStee(Steel steel)
        {

            //调用用户中的修改用户信息方法
            //int rows = modify_stee.Modify_stee();
            //调用获得用户订单信息的方法

            string message = 1 > 0 ? "添加成功" : "添加失败";
            return Content(message, "text / plain");
        }

        public ActionResult SHjixs(string App_bian= "", string shen="", string ming="")
        {
            Session["JHNSHHD"] = App_bian;
            var app = db.Applications.FirstOrDefault(s=>s.AP_bian== App_bian);
            var sjinf = app == null? "" : app.App_Kehu;
            var she=db.Sheji.Where(a=>a.SJ_gs.Contains(sjinf)||a.SJ_Zhua=="通用").ToList();
            if (shen!=""|| ming!="")
            {
                she = she.Where(a => a.SJ_gs.Contains(ming) || a.SJ_gs.Contains(ming)).ToList();
            }
            ViewBag.shjjin = she;
            return View();
        }
    }
}